package charcount;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class CharCount {
	
	public static void main(String[] args) throws FileNotFoundException {
		System.out.println("中文字符:"+chineseCharCount());
		System.out.println("英文字符:"+letterCount());
		System.out.println("数字:"+digitCount());
		System.out.println("符号:"+symbolCount());
		

	}
	
	public static int chineseCharCount() throws FileNotFoundException{
		Scanner sc = new Scanner(new FileInputStream("abc.txt"));
		String data;
		String rc="[\\u4E00-\\u9FA5]";
		int count=0;
		Pattern p=Pattern.compile(rc);
		Matcher m;
		while(sc.hasNextLine()){
			data=sc.nextLine();
			m=p.matcher(data);
			while(m.find())count++;
		}
		
		return count;
	}
	
	public static int letterCount() throws FileNotFoundException{
		Scanner sc = new Scanner(new FileInputStream("abc.txt"));
		String data;
		String rc="[a-zA-Z]";
		int count=0;
		Pattern p=Pattern.compile(rc);
		Matcher m;
		while(sc.hasNextLine()){
			data=sc.nextLine();
			m=p.matcher(data);
			while(m.find())count++;
		}
		
		return count;
	}
	
	
	public static int digitCount() throws FileNotFoundException{
		Scanner sc = new Scanner(new FileInputStream("abc.txt"));
		String data;
		String rc="[0-9]";
		int count=0;
		Pattern p=Pattern.compile(rc);
		Matcher m;
		while(sc.hasNextLine()){
			data=sc.nextLine();
			m=p.matcher(data);
			while(m.find())count++;
		}
		
		return count;
	}
	
	public static int symbolCount() throws FileNotFoundException{
		Scanner sc = new Scanner(new FileInputStream("abc.txt"));
		String data;
		String rc="[\\pP\\pS\\pZ]";
		int count=0;
		Pattern p=Pattern.compile(rc);
		Matcher m;
		while(sc.hasNextLine()){
			data=sc.nextLine();
			m=p.matcher(data);
			while(m.find())count++;
		}
		return count;
	}
	
}
//String s="abcab+dcadcab,fadf,adfaf,aadfa=adf";
//String rc="[a-zA-Z0-9]";
//String r1="^[1-9]\\d{2}-\\d{2}-\\d{2}$";
//String r2="\\d{17}(\\d|X)";
//int count=0;
//Pattern p=Pattern.compile(rc);
//Matcher m=p.matcher(s);
//while(m.find())
//System.out.println(m.start()+"..."+m.end()+"..."+m.group());
//count++;